#!/bin/sh

# Slackware build script for xxkb
# written by Cyril A. Sluchanko
# revision date 2009/04/26

PRGNAM=xxkb
VERSION=1.11
ARCH=${ARCH:-i486}
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}

CWD=$(pwd)
TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

if [ "$ARCH" = "i486" ]; then
  SLKCFLAGS="-O2 -march=i486 -mtune=i686"
 elif [ "$ARCH" = "i686" ]; then
   SLKCFLAGS="-O2 -march=i686 -mtune=i686"
 elif [ "$ARCH" = "x86_64" ]; then
   SLKCFLAGS="-O2 -fPIC"
fi

set -e

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
rm -rf $TMP/$PRGNAM-$VERSION
cd $TMP
tar xvf $CWD/$PRGNAM-$VERSION-src.tar.gz
cd $PRGNAM
chown -R root:root .
chmod -R u+w,go+r-w,a-s .

# We need to patch Imakefile to have xxkb compiled successfully
patch -p1 < $CWD/Imakefile.patch

xmkmf
make
make install DESTDIR=$PKG

mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cp -a LICENSE README README.koi8 README-Linux.koi8 CHANGES.koi8 \
  $PKG/usr/doc/$PRGNAM-$VERSION
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.tgz
